import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

/*
public class Test {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue <String> queue = new LinkedBlockingQueue<>();
        queue.put("123");
        String elem = queue.take();
        System.out.println(elem);
    }
}*/
/*
class MyBlockingQueue{
    private String[] data = new String[1000];
    private volatile int head = 0;
    private volatile int tail = 0;
    private volatile int size = 0;

    public void put(String elem) throws InterruptedException {
        synchronized (this){
          while(size== data.length){
              this.wait();
          }
          data[tail]=elem;
          tail++;
          if(tail== data.length){
              tail=0;
          }
          size++;
          this.notify();
        }
    }
    public String take() throws InterruptedException {
        synchronized (this){
            while(size==0){
                this.wait();
            }
            String ret = data[head];
            head++;
            if(head==data.length){
                head=0;
            }
            size--;
            this.notify();
            return ret;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyBlockingQueue queue = new MyBlockingQueue();
        Thread t1 = new Thread(()->{
            while(true){
                try {
                    String result = queue.take();
                    System.out.println("消费元素"+result);
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t2 = new Thread(()->{
             int num = 1;
             while(true){
                 try {
                     queue.put(num+"");
                     System.out.println("生产元素"+num);
                     num++;
                 } catch (InterruptedException e) {
                     throw new RuntimeException(e);
                 }
             }
        });
        t1.start();
        t2.start();
    }
}*/
/*

public class Test {
    public static void main(String[] args) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("3000");
            }
        },3000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("2000");
            }
        },2000);
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("1000");
            }
        },1000);
        System.out.println("程序启动");
    }
}*/
